﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class admin_News_Manage : System.Web.UI.Page
{
    string sql;
    string zh_Class = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        AdminCs.CheckLoginState();
        if (!IsPostBack)
        {
            list_bind();
        } 
    }

    private void list_bind()
    {

        SqlConnection conn = Class1.DBconnection();
        if (Request.QueryString["zh_Class"] != "")
        {
            zh_Class = Request.QueryString["zh_Class"];
            sql = "select * from ZhanHui where n_Class='" + zh_Class + "' order by n_ID desc";
        }
        else
        {
            sql = "select * from ZhanHui order by n_ID desc";
        }

        SqlDataAdapter da = new SqlDataAdapter(sql, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable dt = ds.Tables[0];

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            if (ds.Tables[0].Rows[i]["n_Title"].ToString().Length > 100)
            {
                ds.Tables[0].Rows[i]["n_Title"] = ds.Tables[0].Rows[i]["n_Title"].ToString().Substring(0, 100) + "...";
            }
        }

        if (dt.Rows.Count > 0)
        {
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = ds.Tables[0].DefaultView;

            pds.AllowPaging = true;
            pds.PageSize =17;
            int curPage;

            if (Request.QueryString["page"] != null)
            {
                curPage = Convert.ToInt32(Request.QueryString["page"]);
            }
            else
            {
                curPage = 1;
            }

            pds.CurrentPageIndex = curPage - 1;
            this.Repeater1.DataSource = pds;
            this.Repeater1.DataBind();
            this.Label1.Text += "<a>共有<font color=red><b>" + ds.Tables[0].Rows.Count.ToString() + "</b></font>条记录</a>&nbsp;";
            this.Label1.Text += "<a>每页显示<font color=red><b>" + pds.PageSize + "</b></font>条</a>&nbsp;";
            this.Label1.Text += "<a>共<font color=red><b>" + pds.PageCount.ToString() + "</b></font>页</a>&nbsp;";
            this.Label1.Text += "<a>当前第<font color=red><b>" + curPage.ToString() + "</b></font>页</a>&nbsp;&nbsp;";
            if (curPage == 1)
            {
                this.Label1.Text += "<a>首页</a>&nbsp;";
                this.Label1.Text += "<a>上一页</a>&nbsp;";
            }
            else
            {
                this.Label1.Text += "<a href='Show_Manage.aspx?page=1&zh_Class=" + zh_Class + "'>首页</a>&nbsp;";
                this.Label1.Text += "<a href='Show_Manage.aspx?page=" + (curPage - 1).ToString() + "&zh_Class=" + zh_Class + "'>上一页</a>&nbsp;&nbsp;";
            }
            if (curPage == pds.PageCount)
            {
                this.Label1.Text += "<a>下一页</a>&nbsp;";
                this.Label1.Text += "<a>尾页</a>&nbsp;";
            }
            else
            {
                this.Label1.Text += "<a href='Show_Manage.aspx?page=" + (curPage + 1).ToString() + "&zh_Class=" + zh_Class + "'>下一页</a>&nbsp;";
                this.Label1.Text += "<a href='Show_Manage.aspx?page=" + pds.PageCount.ToString() + "&zh_Class=" + zh_Class + "'>尾页</a>&nbsp;";
            }

            string HtmlSelectString = "<select onchange=\"javascript:window.location=this.value\">";
            for (int i = 1; i <= pds.PageCount; i++)
            {
                if (i == curPage)
                {
                    HtmlSelectString += "<option value=?page=" + i + "&zh_Class=" + zh_Class + " selected>第" + i + "页</option>";
                }
                else
                {
                    HtmlSelectString += "<option value=?page=" + i + "&zh_Class=" + zh_Class + ">第" + i + "页</option>";
                }
            }
            HtmlSelectString += "</select>";

            this.Label1.Text += "<a>" + HtmlSelectString + "</a>";
        }
        else
        {
            this.Label1.Text = "当前没有记录";
        }
        ds.Dispose();
        da.Dispose();
        conn.Close();
        conn.Dispose();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string aa = "";
        string lm = DropDownList1.SelectedItem.Text;

        if (this.DropDownList1.SelectedItem.Text == "请选择")
        {
            Response.Redirect("Show_Manage.aspx?zh_Class=" + aa);
        }
        else
        {
            Response.Redirect("Show_Manage.aspx?zh_Class=" + lm + "");
        }
    }
}
